package com.chengxiaoxiao.dao.impl;

import com.chengxiaoxiao.dao.ApppptDao;
import com.chengxiaoxiao.domain.Appppt;
import com.chengxiaoxiao.utils.db.BeanHandler;
import com.chengxiaoxiao.utils.db.BeanListHandler;
import com.chengxiaoxiao.utils.db.DBAssist;
import com.chengxiaoxiao.utils.db.DBCPUtil;

import java.util.List;

public class ApppptDaoImpl implements ApppptDao {

    private DBAssist da = new DBAssist(DBCPUtil.getDataSource());

    @Override
    public void add(Appppt appppt) {
        da.update("insert into appppt(title,picture) values(?,?)", appppt.getTitle(), appppt.getPicture());
    }

    @Override
    public void update(Appppt appppt) {
        da.update("update appppt set title=?,picture=? where id=?", appppt.getTitle(), appppt.getPicture(),appppt.getId());

    }

    @Override
    public void delete(long id) {
        da.update("delete from appppt where id=?", id);
    }

    @Override
    public List get() {
        return (List) da.query("select * from appppt",new BeanListHandler(Appppt.class));
    }

    @Override
    public Appppt getbyId(long id) {
        return (Appppt) da.query("select * from appppt where id=?",new BeanHandler(Appppt.class),id);
    }

    @Override
    public List getListPage(int startIndex, int pageSize) {
        return null;
    }
}
